﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeBehind="Stocking.aspx.cs" Inherits="Project_Udrinkwater.Stock.Stocking" %>
<%@ Register TagPrefix="dxe" Namespace="DevExpress.Web.ASPxEditors" Assembly="DevExpress.Web.v12.2, Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    
    <script language="javascript" type="text/javascript">
            // <![CDATA[


      
       var combo = null;
       var isUpdating = false;

       function ShowPopup() {
           pc.Show();
          
       }

       function btnYes_Click(s, e) {
           ClosePopup(true);
       }

       function btnNo_Click(s, e) {
           ClosePopup(false);
       }
            // ]]>
        </script>
    <dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" runat="server" 
        GridViewID="gridMain" PaperKind="A4">
        <Styles>
            <Default Font-Names="Angsana New">
            </Default>
        </Styles>
    </dx:ASPxGridViewExporter>
    <dx:ASPxGridViewExporter ID="ASPxGridViewExporter2" runat="server" 
        GridViewID="ASPxGridView1">
        <Styles>
            <Default Font-Names="Angsana New">
            </Default>
        </Styles>
    </dx:ASPxGridViewExporter>
    <asp:Panel ID="Panel1" runat="server">
         <fieldset>
        <legend>รายการใบเบิก/รับสินค้า</legend>
        <asp:Panel ID="Panel6" runat="server">
                        <table style="width: 100%">
                            <tr>
                                <td align="right">
                                    <table style="width: 100%">
                                        <tr>
                                            <td align="right" style="width: 315px; height: 27px;">
                                                <dxe:ASPxLabel ID="ASPxLabel3" runat="server" Text="ค้นหาตั้งแต่วันที่:">
                                                </dxe:ASPxLabel>
                                            </td>
                                            <td style="width: 210px; height: 27px;">
                                                <dxe:ASPxDateEdit ID="deStart0" runat="server" DisplayFormatString="dd/MM/yyyy" 
                                                    EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                                                </dxe:ASPxDateEdit>
                                            </td>
                                            <td align="right" style="width: 108px; height: 27px;">
                                                <dxe:ASPxLabel ID="ASPxLabel4" runat="server" Text="ถึงวันที่:">
                                                </dxe:ASPxLabel>
                                            </td>
                                            <td style="width: 198px; height: 27px;">
                                                <dxe:ASPxDateEdit ID="edEnd0" runat="server" DisplayFormatString="dd/MM/yyyy" 
                                                    EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                                                </dxe:ASPxDateEdit>
                                            </td>
                                            <td style="height: 27px" colspan="2">
                                                <dxe:ASPxButton ID="ASPxButton8" runat="server" onclick="ASPxButton8_Click" 
                                                    Text="ค้นหา">
                                                </dxe:ASPxButton>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left" style="width: 315px">
                                                <dxe:ASPxButton ID="ASPxButton9" runat="server" onclick="ASPxButton9_Click" 
                                                    Text="ค้นหารายการสินค้าเข้าออก" Width="200px">
                                                </dxe:ASPxButton>
                                            </td>
                                            <td style="width: 210px">
                                                &nbsp;</td>
                                            <td align="right" style="width: 108px">
                                                &nbsp;</td>
                                            <td style="width: 198px">
                                                &nbsp;</td>
                                            <td align="right">
                                                <dxe:ASPxButton ID="ASPxButton11" runat="server" Text="พิมพ์รายงาน .pdf" 
                                                    onclick="ASPxButton11_Click" Width="120px">
                                                </dxe:ASPxButton>
                                            </td>
                                            <td align="right">
                                                <dxe:ASPxButton ID="ASPxButton13" runat="server" onclick="ASPxButton13_Click" 
                                                    Text="พิมพ์รายงาน .xml" Width="120px">
                                                </dxe:ASPxButton>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </asp:Panel>
        <dx:ASPxGridView ID="gridMain" runat="server" Width="100%" 
        AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
        KeyFieldName="Stock_ID">
        <Columns>
            <dx:GridViewCommandColumn VisibleIndex="5" Caption="ทำรายการ" Width="100px">
                <EditButton Visible="True" Text="แก้ไข">
                </EditButton>
                <NewButton Visible="True" Text="เพิ่ม">
                </NewButton>
                <DeleteButton Visible="True" Text="ลบ">
                </DeleteButton>
                <ClearFilterButton Visible="True">
                </ClearFilterButton>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataTextColumn FieldName="Stock_ID" ReadOnly="True" 
                VisibleIndex="0" Visible="False">
                <EditFormSettings Visible="False" />
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Stock_doc_NO" 
                ReadOnly="True" VisibleIndex="1" Caption="เลขที่เอกสาร" Width="200px">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataDateColumn FieldName="Stock_Date" VisibleIndex="2" 
                Caption="วันที่เอกสาร" Width="200px">
                <PropertiesDateEdit DisplayFormatString="dd/MM/yyyy">
                </PropertiesDateEdit>
                <EditFormSettings Visible="True" />
            </dx:GridViewDataDateColumn>
            <dx:GridViewDataComboBoxColumn FieldName="Act_Employee_ID" VisibleIndex="3" 
                Caption="พนักงานทำรายการ">
                <PropertiesComboBox DataSourceID="sdsEmp" TextField="Name" 
                    ValueField="Employee_ID" TextFormatString="{0} {1} {2}">
                    <Columns>
                        <dx:ListBoxColumn FieldName="Employee_ID" />
                        <dx:ListBoxColumn FieldName="Name" />
                        <dx:ListBoxColumn FieldName="Department_Name" />
                        <dxe:ListBoxColumn FieldName="Employee_ID" />
                        <dxe:ListBoxColumn FieldName="Name" />
                        <dxe:ListBoxColumn FieldName="Department_Name" />
                        <dxe:ListBoxColumn FieldName="Employee_ID" />
                        <dxe:ListBoxColumn FieldName="Name" />
                        <dxe:ListBoxColumn FieldName="Department_Name" />
                    </Columns>
                </PropertiesComboBox>
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataTextColumn Caption="ดูและเพิ่มรายการ" 
                VisibleIndex="4" Width="150px">
                <EditFormSettings Visible="False" />
                <DataItemTemplate>
                    <asp:LinkButton ID="lkDetail" CommandName="cmdDetial" 
                        CommandArgument='<%# Eval("Stock_ID") %>' ToolTip="ดูรายการของเอกสารรหัสนี้" 
                        runat="server" oncommand="lkDetail_Command">ดูและเพิ่มรายการ</asp:LinkButton>
                </DataItemTemplate>
            </dx:GridViewDataTextColumn>
        </Columns>
        <Settings ShowFilterRow="True" />
        <SettingsText GroupPanel="ลากคอลัมมาที่นี่เพื่อจัดเรียงตามคอลัมนั้น" />
    </dx:ASPxGridView>
    </fieldset>
    </asp:Panel>
    <asp:Panel ID="Panel2" runat="server" Visible="False">
         <fieldset>
        <legend>ค้นหารายการเบิก/รับสินค้า</legend>
           
       <asp:Panel ID="Panel5" runat="server">
             <table style="width: 100%">
                 <tr>
                     <td align="left" style="width: 315px">
                         <dxe:ASPxButton ID="ASPxButton10" runat="server" onclick="ASPxButton10_Click" 
                             Text="กลับหน้ารายใบเบิก/รับสินค้า" Width="200px">
                         </dxe:ASPxButton>
                     </td>
                     <td style="width: 210px">
                         &nbsp;</td>
                     <td align="right" style="width: 108px">
                         &nbsp;</td>
                     <td style="width: 198px">
                         &nbsp;</td>
                     <td align="right" colspan="2">
                         &nbsp;</td>
                 </tr>
                 <tr>
                     <td align="right" style="width: 315px">
                         <dxe:ASPxLabel ID="ASPxLabel2" runat="server" Text="ค้นหาตั้งแต่วันที่:">
                         </dxe:ASPxLabel>
                     </td>
                     <td style="width: 210px">
                         <dxe:ASPxDateEdit ID="deStart" runat="server" 
                             DisplayFormatString="dd MMMM yyyy" EditFormat="Custom" 
                             EditFormatString="dd/MM/yyyy">
                         </dxe:ASPxDateEdit>
                     </td>
                     <td align="right" style="width: 108px">
                         <dxe:ASPxLabel ID="ASPxLabel1" runat="server" Text="ถึงวันที่:">
                         </dxe:ASPxLabel>
                     </td>
                     <td style="width: 198px">
                         <dxe:ASPxDateEdit ID="edEnd" runat="server" DisplayFormatString="dd MMMM yyyy" 
                             EditFormat="Custom" EditFormatString="dd/MM/yyyy">
                         </dxe:ASPxDateEdit>
                     </td>
                     <td colspan="2">
                         <dxe:ASPxButton ID="ASPxButton7" runat="server" onclick="ASPxButton7_Click" 
                             Text="ค้นหา">
                         </dxe:ASPxButton>
                     </td>
                 </tr>
                 <tr>
                     <td align="right" style="width: 315px">
                         &nbsp;</td>
                     <td style="width: 210px">
                         &nbsp;</td>
                     <td align="right" style="width: 108px">
                         &nbsp;</td>
                     <td style="width: 198px">
                         &nbsp;</td>
                     <td>
                         <dxe:ASPxButton ID="ASPxButton12" runat="server" onclick="ASPxButton12_Click" 
                             Text="พิมพ์รายงาน .pdf" Width="120px">
                         </dxe:ASPxButton>
                     </td>
                     <td>
                         <dxe:ASPxButton ID="ASPxButton14" runat="server" onclick="ASPxButton14_Click" 
                             Text="พิมพ์รายงาน .xml" Width="120px">
                         </dxe:ASPxButton>
                     </td>
                 </tr>
             </table>
         </asp:Panel>
        <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlStockListSert" KeyFieldName="Product_ID" Width="100%">
            <Columns>
                <dx:GridViewDataTextColumn FieldName="Stock_doc_NO" ReadOnly="True" 
                    VisibleIndex="0" Caption="เลขที่เอกสาร">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataDateColumn FieldName="Stock_Date" VisibleIndex="1" 
                    Caption="วันที่">
                </dx:GridViewDataDateColumn>
                <dx:GridViewDataTextColumn FieldName="Product_Name" VisibleIndex="3" 
                    Caption="ชื่อสินค้า">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="Amount" VisibleIndex="5" Caption="จำนวน">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="Transfer_Category_Name" VisibleIndex="4" 
                    Caption="ประเภทการโอนย้าย">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="Warehouse_name" VisibleIndex="6" 
                    Caption="คลัง">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="Product_ID" ReadOnly="True" 
                    VisibleIndex="2" Caption="รหัสสินค้า">
                </dx:GridViewDataTextColumn>
            </Columns>
        </dx:ASPxGridView>
        </fieldset>
        <asp:SqlDataSource ID="SqlStockListSert" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
            SelectCommand="SELECT TB_Stock.Stock_doc_NO, TB_Stock.Stock_Date, TB_Stock.Act_Employee_ID, TB_Stock_List.Product_ID, TB_Stock_List.Transfer_Category_ID, TB_Stock_List.Warehouse_ID, TB_Stock_List.Amount, TB_Product.Product_Name, TB_Tranfer_Category.Transfer_Category_Name, TB_Warehouse.Warehouse_name FROM TB_Stock INNER JOIN TB_Stock_List ON TB_Stock.Stock_ID = TB_Stock_List.Stock_ID INNER JOIN TB_Tranfer_Category ON TB_Stock_List.Transfer_Category_ID = TB_Tranfer_Category.Transfer_Category_ID INNER JOIN TB_Warehouse ON TB_Stock_List.Warehouse_ID = TB_Warehouse.Warehouse_ID LEFT OUTER JOIN TB_Product ON TB_Stock_List.Product_ID = TB_Product.Product_ID
WHERE TB_Stock.Stock_Date BETWEEN @sStart AND @sEnd" 
            onselecting="SqlStockListSert_Selecting">
            <SelectParameters>
                <asp:SessionParameter Name="sStart" SessionField="sStart" />
                <asp:SessionParameter Name="sEnd" SessionField="sEnd" />
            </SelectParameters>
        </asp:SqlDataSource>
    </asp:Panel>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
    DeleteCommand="DELETE FROM TB_Stock WHERE (Stock_ID = @Stock_ID)" 
    InsertCommand="INSERT INTO TB_Stock(Stock_Date, Act_Employee_ID) VALUES (@Stock_Date, @Act_Employee_ID)" 
    SelectCommand="SELECT Stock_ID, Stock_doc_NO, Stock_Date, Act_Employee_ID FROM TB_Stock WHERE Stock_Date BETWEEN @sStart AND @sEnd 
" 
    
        
        UpdateCommand="UPDATE TB_Stock SET Stock_Date =?, Act_Employee_ID =?" 
        onselecting="SqlDataSource1_Selecting">
        <DeleteParameters>
            <asp:Parameter Name="Stock_ID" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Stock_Date" />
            <asp:Parameter Name="Act_Employee_ID" />
        </InsertParameters>
        <SelectParameters>
            <asp:SessionParameter Name="sStart" SessionField="sStart" />
            <asp:SessionParameter Name="sEnd" SessionField="sEnd" />
        </SelectParameters>
</asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsFloor" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        
        SelectCommand="SELECT [Floor_ID], [Floor_Name] FROM [TB_Floor]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsWarehouse" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT [Warehouse_name], [Warehouse_ID] FROM [TB_Warehouse]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsTranferCate" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT * FROM [TB_Tranfer_Category]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsEmp" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        
        SelectCommand="SELECT TB_Employee.Employee_ID, TB_Employee.FirstName + ' ' + TB_Employee.LastName AS Name, TB_Department.Department_Name FROM TB_Employee INNER JOIN TB_Department ON TB_Employee.Departmernt_ID = TB_Department.Department_ID">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sqlProcate" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT * FROM [TB_Product_Category]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="sqlProduct" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        
        
        
        SelectCommand="SELECT [Product_ID], ([Product_Name] +' : จำนวนทีเหลือในคลัง '+ convert(nvarchar,[In_Stock])+' '+ (SELECT TB_Unit_Category.Unit_Name FROM TB_Unit_Category WHERE TB_Product.Product_Unit=TB_Unit_Category.Unit_ID)) As ProductName ,[In_Stock] FROM [TB_Product]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sqlUnit" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT * FROM [TB_Unit_Category]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="sqlValStock" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT [Product_ID], [In_Stock] FROM [TB_Product] WHERE ([Product_ID] = @Product_ID)"
        onselecting="sqlValStock_Selecting" >
        
        <SelectParameters>
            <asp:SessionParameter Name="Product_ID" SessionField="Product_ID" 
                Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sqlProductAmountAll" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT [In_Stock], [Product_ID] FROM [TB_Product]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="sqlProductAmount" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        
        SelectCommand="SELECT In_Stock, Product_ID FROM TB_Product WHERE (Product_ID = @Product_ID)">
        <SelectParameters>
            <asp:Parameter Name="Product_ID" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT [Floor_ID], [Floor_Name] FROM [TB_Floor] WHERE ([Warehouse_ID] = @Warehouse_ID)">
        <SelectParameters>
            <asp:Parameter DefaultValue="@Warehouse_ID" Name="Warehouse_ID" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sqlInStock" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT TB_Product.Product_ID, TB_InStock.In_Stock FROM TB_InStock INNER JOIN TB_Product ON TB_InStock.Product_ID = TB_Product.Product_ID">
    </asp:SqlDataSource>
</asp:Content>
